@isTest
private class IntentProductControllerTest {
    static testMethod void testMethod1() {
        // 客户
        Account acc = TestUtils.createAccount();
        acc.Level__c = '一级医院';
        insert acc;

        // 业务机会
        Opportunity opp = TestUtils.createOpportunity();
        opp.AccountId = acc.Id;
        insert opp;

        // 产品
        Product__c p = TestUtils.createProduct();
        p.Purpose__c = '仪器报价用';
        p.Category3__c = '仪器';
        p.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        insert p;

        MaccuraProject__c mp = new MaccuraProject__c();
        mp.MatchingInstrument__c = p.Id;
        mp.Name = '项目1';
        insert mp;

        Product__c p1 = TestUtils.createProduct();
        p1.Purpose__c = '仪器报价用';
        p1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        insert p1;


        // 价格
        Price__c price = TestUtils.createPrice();
        price.Product__c = p.Id;
        insert price;

        IntentProduct__c ip = new IntentProduct__c();
        ip.Product__c = p.Id;
        ip.Quantity__c = 1;
        ip.SalesPrice__c = 1;
        ip.Opportunity__c = opp.Id;
        insert ip;


        PlannedUseProjects__c pup = new PlannedUseProjects__c();
        pup.IntentionalProduct__c = ip.Id;
        pup.MaccuraProject__c = mp.Id; 
        pup.Type__c = '新增';
        pup.SpecimenVolume__c = 10;
        insert pup;

        // ---------------------新建-----------------------
        PageReference page = new PageReference('/apex/IntentProduct?oppid=' + opp.Id);
        System.Test.setCurrentPage(page);
        IntentProductController ipc = new IntentProductController();
        ipc.oppId = opp.Id;
        ipc.init();
        ipc.setNil();
        ipc.getRegent();
        ipc.getEquipment();
        Map<String,Object> tmp = new Map<String,Object>();
        tmp.put('name', '测稀释');
        tmp.put('isEuip',false);

        ipc.paramJson = EncodingUtil.urlEncode(JSON.serialize(tmp), 'UTF-8');

        ipc.search();
        List<IntentProductController.PlanProjectBean> plist =new List<IntentProductController.PlanProjectBean>();
        plist.add(new IntentProductController.PlanProjectBean(mp));
        List<IntentProductController.ProductBean> reList = new List<IntentProductController.ProductBean>();
        reList.add(new IntentProductController.ProductBean(ip,true,false,opp,plist));
        ipc.saveJson = EncodingUtil.urlEncode(JSON.serialize(reList), 'UTF-8');

        //ipc.resJson = EncodingUtil.urlEncode(JSON.serialize(ipc.ipbList), 'UTF-8');
        ipc.save();

        //System.assertEquals(1, q.size());

        // ---------------------编辑-----------------------

    }
}